package offer;

public class Solution16 {
    public double myPow(double x, int n) {
        return n >= 0 ? quick(x, n) : 1 / quick(x, -(long) n);
    }

    private double quick(double x, long n) {
        if (n == 0) {
            return 1.0;
        }
        double y = quick(x, n / 2);
        return n % 2 == 0 ? y * y : y * y * x;
    }
}
